package com.wy.business.market.service.actions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.wy.business.market.service.services.NewsManageService;
import com.wy.framework.actions.AbstractBaseAction;
import com.wy.framework.dao.ErrorSqlException;
import com.wy.framework.exceptions.ServiceException;
import com.wy.component.dataConvert.JsonUtil;

/**
 * 项目名称：openportal
 * 类名称：NewsAction
 * 类描述：资讯汇聚
 * 创建人：张旭星
 * 创建时间：2016-3-16 下午2:56:02
 * 修改人：张旭星
 * 修改时间：2016-3-16 下午2:56:02
 * 版本信息：@version 1.0
 * Copyright (c) 2016万雍科技（上海）有限公司-版权所有  
 * 修改备注：
 * @version 
 */
@ParentPackage("json")
@Namespace("/service/news")
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })
public class NewsAction extends AbstractBaseAction {
	private static final long serialVersionUID = 1L;
	private static Log logger = LogFactory.getLog(NewsAction.class);

	@Autowired
	private NewsManageService newsManageService;
	
	private List<Map> rows;
	private List<Map> orgInfo;
	private String id;

	/**
	 * Function Name               showThumbList                                   
	 * @return
	 * @throws ServiceException          		             
	 * @description 缩略图列表展示方式
	 * Modify History:              Date             Programmer       Notes
	 *                            ---------        ---------------  ---------
	 *                      2016-1-4 下午1:46:43           张旭星                     Initial
	 **********************************************************************
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Action(value = "showThumbList", results = { @Result(name = "success", location = "/jsps/apiEncrypt.jsp") })
	public String showThumbList() throws ServiceException {
		String currentPage = ServletActionContext.getRequest().getParameter("currentPage");
		String pageSize = ServletActionContext.getRequest().getParameter("pageSize");
		try {
			rows = newsManageService.showThumbList(currentPage,pageSize);
		} catch (ErrorSqlException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	/**
	 * Function Name               updateViews                                   
	 * @return
	 * @throws ServiceException          		             
	 * @description 增加访问量
	 * Modify History:              Date             Programmer       Notes
	 *                            ---------        ---------------  ---------
	 *                      2016-1-4 下午1:46:43           张旭星                     Initial
	 **********************************************************************
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Action(value = "updateViews", results = { @Result(name = "success", location = "/jsps/apiEncrypt.jsp") })
	public String updateViews() throws ServiceException {
		try {
			String newsId = ServletActionContext.getRequest().getParameter("newsId");
			rspCode = newsManageService.updateViews(newsId);
		} catch (ErrorSqlException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	

	public List<Map> getRows() {
		return rows;
	}

	public List<Map> getOrgInfo() {
		return orgInfo;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getTotal() {
		if (rows == null) {
			return 0;
		} else {
			return rows.size();
		}
	}

}
